package study.mybatis.multi.datasource.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import study.mybatis.multi.datasource.mapper.account.AccountBaseEO;
import study.mybatis.multi.datasource.mapper.account.AccountBaseMapper;
import study.mybatis.multi.datasource.mapper.user.UserBaseEO;
import study.mybatis.multi.datasource.mapper.user.UserBaseMapper;

@Slf4j
@Service("userService")
public class UserService {

    @Autowired
    private UserBaseMapper userBaseMapper;
    @Autowired
    private AccountBaseMapper accountBaseMapper;

    @Transactional
    public void checkinUser(boolean isThrowEx) {
        UserBaseEO ubEO = new UserBaseEO();
        ubEO.setUbLoginName("wzj");
        ubEO.setUbLoginPwd("123123");
        userBaseMapper.insert(ubEO);
        if (1 == 1) {
            throw new RuntimeException("我是一个运行时异常");
        }
        AccountBaseEO abEO = new AccountBaseEO();
        abEO.setAbUbId(ubEO.getUbId());
        accountBaseMapper.insert(abEO);
    }
}
